﻿using System;
using System.Collections.Generic;
using RockHopper.Common.Model;

namespace RockHopper.Common.Data
{
    public abstract class SettingsRepositoryBase : ISettingsRepository
    {
        protected abstract IDictionary<string, object> Properties { get; }

        public double Vdot
        {
            get
            {
                if (!Properties.ContainsKey("VDOT"))
                    Properties.Add("VDOT", "50");
                return double.Parse(Properties["VDOT"].ToString());
            }
            set
            {
                Properties["VDOT"] = value;
            }
        }

        public PaceUnitType PaceUnits
        {
            get
            {
                if (!Properties.ContainsKey("PaceUnits"))
                    Properties.Add("PaceUnits", PaceUnitType.Kilometres.ToString());
                return (PaceUnitType)Enum.Parse(typeof(PaceUnitType), Properties["PaceUnits"].ToString(), true);
            }
            set
            {
                Properties["PaceUnits"] = value.ToString();
            }
        }

        public string RacePredictions
        {
            get
            {
                if (!Properties.ContainsKey("RacePredictions"))
                    Properties["RacePredictions"] = "";
                return Properties["RacePredictions"].ToString();
            }
            set
            {
                Properties["RacePredictions"] = value;
            }
        }

        public int RestingHeartRate
        {
            get
            {
                if (!Properties.ContainsKey("RestingHeartRate"))
                    Properties.Add("RestingHeartRate", "60");
                return int.Parse(Properties["RestingHeartRate"].ToString());
            }
            set
            {
                Properties["RestingHeartRate"] = value;
            }
        }

        public int MaximumHeartRate
        {
            get
            {
                if (!Properties.ContainsKey("MaximumHeartRate"))
                    Properties.Add("MaximumHeartRate", "180");
                return int.Parse(Properties["MaximumHeartRate"].ToString());
            }
            set
            {
                Properties["MaximumHeartRate"] = value;
            }
        }
    }
}